package com.huaqin.customer.expansion;

import java.util.ArrayList;
import java.util.List;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.util.Log;

public class FunctionConfig extends BroadcastReceiver{
	private static String mTitle = null;
	private static String mShowConfig = null;
	private static List<String> mShowCongifItem;

	public static void setDialogTitle(String title){
		mTitle = title;
	}

	public static void setDialogMsgConfig(String config){
		mShowConfig = config;
		Log.i("FunctionConfig", "mShowConfig is " + mShowConfig);
	}
	
	public static String getDialogMsgConfig(){
	    return mShowConfig;
	}
	
	public static void addConfigItem(String item){
		if(mShowCongifItem == null){
			mShowCongifItem = new ArrayList<String>();
		}
		mShowCongifItem.add(item);
		Log.i("FunctionConfig", "mShowConfig is " + mShowConfig);
	}
	
	public static List<String> getConfigItem(){
	    return mShowCongifItem;
	}

	public static String getDialogTitle(){
		return mTitle != null ? mTitle : "SalesTracker Info:";
	}

	private static void showDialog(Context context, String type){
		Intent intent = new Intent(context, ConfirmDialogActivity.class);
		intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY|Intent.FLAG_ACTIVITY_NEW_TASK);
		intent.putExtra("DialogType", type);
		context.startActivity(intent);
	}
	
	@Override
	public void onReceive(final Context context, Intent intent) {
		// TODO Auto-generated method stub
		
		Log.i("FunctionConfig", " >> onReceive");
		
		if (null == intent) {
			return;
		}

		final String action = intent.getAction();
		new Handler().postAtTime(new Runnable(){
			@Override
			public void run() {
				if (action.equals("android.provider.Telephony.SECRET_CODE")) {
					showDialog(context, "AppInfoDisplay");
		        }
			}
			
		}, 10);
	}
}
